<template>
  <div>
   <el-row>
     <el-col :span="24">
        <div class="header">
         <label for="assistant" style="font-size:20px;font-weight: 600; line-height: 40px;margin-right:5px">已提交信息</label>
         <a :href="loadFileUrl" @click="loadFiles" download><el-button type="success" style="margin-left: 20px;">导出excel</el-button></a>
         <span class="search">
         <el-select v-if="userInfo.username === 'admin'" style="width: 160px;margin-left: 40px;" @change="currChange" v-model="school" placeholder="选择或输入学校" clearable filterable>
            <el-option v-for="item in schools" :key="item.sch_id" :label="item.sch_name" :value="item.sch_id"></el-option>
          </el-select>
          <el-date-picker
            v-model="datetime"
            unlink-panels
            type="daterange"
            style="width: 280px; margin-left: 20px;"
            range-separator="至 "
            start-placeholder="开始日期"
            end-placeholder="  结束日期">
            </el-date-picker>
         <el-button type="primary" @click="search">搜索</el-button>
       </span>
       </div>
     </el-col>
   </el-row>
   <el-row style="border-top: 1px solid black; margin-top: 15px">
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%;margin-bottom: 10px"
        @selection-change="handleSelectionChange"
        :row-style="showSex">
        <el-table-column
        type="selection"
        width="55">
        </el-table-column>
        <el-table-column
          prop="id"
          label="id"
          width="90">
        </el-table-column>
        <el-table-column
          label="学校"
          prop="sch_name"
          width="190">
        </el-table-column>
        <el-table-column
          label="学习时间"
          prop="learn_time"
          width="210">
        </el-table-column>
        <el-table-column
          label="提交时间"
          prop="gmt_create"
          width="200">
        </el-table-column>
        <el-table-column
          label="学习形式"
          prop="learn_ways"
          width="200">
        </el-table-column>
        <el-table-column
          label="参加人员"
          prop="join_person"
          width="220">
        </el-table-column>
        <el-table-column
          label="报告人"
          prop="reporter"
          width="150">
        </el-table-column>
        <el-table-column
          label="报告人职务"
          prop="reporter_career"
          width="150">
        </el-table-column>
        <el-table-column
        label="操作"
        width="250">
        <template slot-scope="scope">
          <!-- name的值是配置路由文件对某界面的命名name，接受值this.$router.params.id -->
          <router-link :to="{name: 'consultsDetail',
                            params: {id: scope.row.id,
                                     last: '3',
                                     searchCheck: searchCheck
                                    }
                            }" 
                            class="btn-link edit-btn">
          查看详情
          </router-link>
          <router-link :to="{name: 'consultsEdit',
                            params: {id: scope.row.id,
                                     last: '3',
                                     searchCheck: searchCheck
                                    }
                            }" 
                            class="btn-link edit-btn1">
          编辑
          </router-link>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            @click.stop="confirmDelete(scope.row)"
            >删除</el-button>
        </template>
      </el-table-column>
      </el-table>
   </el-row>
   <el-pagination
    v-show="allPage>1"
    layout="prev, pager, next"
    :page-count="allPage"
    :current-page="nowPage"
    @current-change="goPage" 
    class="pull-right" background>
  </el-pagination>
 </div>
</template>

<script>
import http from '../../../assets/js/http'

export default {
  data() {
    return {
      allPage: 1,
      nowPage: 1,
      tableData: [],
      option1: [{
        value: '1',
        label: '男'
      }, {
        value: '2',
        label: '女'
      }],
      form: {
        sch: '',
        sch_name: '',
        name: '',
        idcard: '',
        sex: ''
      },
      school: '',
      datetime: '',
      dialogFormVisible: false,
      multipleSelection: [],
      selectId: [],
      userInfo: Lockr.get('userInfo'),
      schools: [],
      loading: true,
      searchCheck: {},
      loadFileUrl: ''
    }
  },
  activated() {},
  watch: {},
  created() {
    this.init()
  },
  mounted() {},
  methods: {
    init () {
      // console.log(this.userInfo)
      this.getSchoolsInfo()
      this.getAllInfo()
    },
    getSchoolsInfo () {
      this.apiPost('admin/Info/schoolList').then((res) => {
        this.handelResponse(res, (data) => {
          console.log(res)
          this.schools = res.data
        })
      })
    },
    currChange (val) {
      console.log(val)
    },
    search () {
      this.getAllInfo()
    },
    loadFiles () {
      this.loadFileUrl = 'http://8.142.34.26:8096/php/index.php/admin/excel/expshopsss?'
      console.log(this.multipleSelection)
      for (var i = 0; i < this.multipleSelection.length; i++) {
        if (i === 0) {
          this.loadFileUrl += 'info_id[' + i + ']=' + this.multipleSelection[i].id
        } else {
          this.loadFileUrl += '&info_id[' + i + ']=' + this.multipleSelection[i].id
        }
      }
      // this.reload()
      // this.$router.push({ path: 'file/list' })
      console.log(this.loadFileUrl)
    },
    getAllInfo () {
      if (this.datetime !== null) {
        for (var i = 0; i < 2; i++) {
          this.datetime[i] = moment(this.datetime[i]).format('YYYY-MM-DD')
        }
      } else if (this.datetime === null) {
        this.datetime = []
      }
      const data = {
        page: this.nowPage,
        keyword: { starttime: this.datetime[0], endtime: this.datetime[1], sch_id: this.school }
      }
      console.log(data)
      this.apiPost('admin/Info/InfosAll', data).then((res) => {
        this.handelResponse(res, (data) => {
          console.log(res.data)
          this.tableData = []
          res.data.data.forEach((element) => {
            var arr1 = []
            for (var j = 0; j < element.join_person.length; j++) {
              if (element.join_person[j] === '0') {
                arr1.push('校党委中心组成员，')
              } else if (element.join_person[j] === '1') {
                arr1.push('全体校领导，')
              } else if (element.join_person[j] === '2') {
                arr1.push('全体中层以上党员干部，')
              } else if (element.join_person[j] === '3') {
                arr1.push('各单位/部门主要负责人，')
              } else if (element.join_person[j] === '4') {
                arr1.push('副处级及以上干部，')
              } else if (element.join_person[j] === '5') {
                arr1.push('二级党组织书记，')
              } else if (element.join_person[j] === '6') {
                arr1.push('其他，')
              }
            }
            element.join_person = arr1

            var arr = []
            // console.log(element.learn_ways.length)
            for (var i = 0; i < element.learn_ways.length; i++) {
              if (element.learn_ways[i] === '0') {
                arr.push('集体学习研讨， ')
              } else if (element.learn_ways[i] === '1') {
                arr.push('个人自学， ')
              } else if (element.learn_ways[i] === '2') {
                arr.push('专题调研， ')
              } else if (element.learn_ways[i] === '3') {
                arr.push('扩大会， ')
              } else if (element.learn_ways[i] === '4') {
                arr.push('其他， ')
              }
            }
            element.learn_ways = arr
            // console.log(element.learn_ways)
            // console.log(element)
            this.tableData.push({
              id: element.id,
              sch_name: element.sch_name,
              learn_time: element.learn_start_time + ' 至 ' + element.learn_end_time,
              learn_ways: element.learn_ways,
              join_person: element.join_person,
              reporter: element.reporter,
              reporter_career: element.reporter_career,
              gmt_create: element.gmt_create
            })
          })
          this.allPage = data.last_page
          _g.closeGlobalLoading()
          this.loading = false
        })
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    goPage(num) {
      console.log(num)
      this.nowPage = num
      this.getAllInfo()
    },
    confirmDelete(item) {
      let data = {
        id: item.id
      }
      console.log(data)
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.apiPost('admin/Info/delInfoById', data).then(res => {
          this.handelResponse(res, data => {
            _g.toastMsg('success', res.data)
            this.getAllInfo()
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  },
  mixins: [http]
}
</script>

<style scoped>
.edit-btn1 {
  background-color: #e6a23c;
}
/* .search {
  display: inline-block;
  width: 80%;
} */
</style>
